package com.zx.dsptuneup_cloud.Tools;

import java.io.IOException;
import java.net.*;

public class UDPClient {
	public static byte[] sendAndReturn(byte[] data,InetAddress address,int port)throws IOException{
        //创建数据报
        DatagramPacket packet=new DatagramPacket(data,data.length,address,port);
        //创建DatagramSocket,实现数据发送和接收
        DatagramSocket socket=new DatagramSocket();
        //向服务器端发送数据报
        socket.send(packet);
        //接收服务器端响应的数据
        byte[] data2=new byte[1024];
        DatagramPacket packet2=new DatagramPacket(data2,data2.length);
        socket.setSoTimeout(5 * 1000);
        socket.receive(packet2);
		return data2;
	}
	public static void send(byte[] data,InetAddress address,int port)throws IOException{
			DatagramPacket packet=new DatagramPacket(data,data.length,address,port);
			//创建DatagramSocket,实现数据发送和接收
			DatagramSocket socket=new DatagramSocket();
			//向服务器端发送数据报
			socket.send(packet);
			socket.close();
	}
}
